<?php
/*
Plugin Name: Archives
Plugin URI: http://www.yhustc.com/
Description: 日志归档
Author: yhustc
Version: 1.0
Author URI: http://www.yhustc.com/
*/

class ArchivesWidget extends Widget
{
	function render($data=array())
	{
		$archives = S("archives");
		if(!$archives)
		{
			$Dao = new Model();
			$sql = "SELECT DISTINCT EXTRACT( YEAR_MONTH FROM `post_date` ) AS AddYearMonth FROM `".C("DB_PREFIX")."posts` ORDER BY AddYearMonth DESC";	
			$archives = $Dao->query($sql);
			S("archives",$archives);
		}

		foreach($archives as &$value)
			$value["AddYearMonth"] = substr($value["AddYearMonth"],0,4)."-".substr($value["AddYearMonth"],4);
		
		$this->assign("archives",$archives);
		return $this->renderFile();
	}
}
?>